package adapter

import "fmt"

// 目标Target接口
type Target interface {
	Request()
}

// 被适配Adaptee接口
type Adaptee interface {
	SpecificRequest()
}

type XiaoMiAdaptee struct{}

func (xma XiaoMiAdaptee) SpecificRequest() {
	fmt.Println("This is a specific request from Xiao Mi")
}

type HuaWeiAdaptee struct{}

func (hwa HuaWeiAdaptee) SpecificRequest() {
	fmt.Println("This is a specific request from Hua Wei")
}

// 适配器Adapter角色
type Adapter struct {
	Adaptee
}

// 使用工厂函数创建Adapter和Adaptee实例
func (a Adapter) Request() {
	a.SpecificRequest()
}

func NewAdapter(adaptee Adaptee) Adapter {
	return Adapter{
		Adaptee: adaptee,
	}
}

func NewAdaptee(t string) Adaptee {
	switch t {
	case "XiaoMi":
		return XiaoMiAdaptee{}
	case "HuaWei":
		return HuaWeiAdaptee{}
	default:
		return nil
	}
}
